package cgb2202.recruitment01.mapper;

import cgb2202.recruitment01.entity.Intention;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface IntentionMapper {

    @Select("select intention.annual_salary,intention.desired_industry,intention.desired_location,intention.desired_job from users,intention where users.email=#{email} and users.id=intention.uid")
    @Result(property = "annualSalary", column = "annual_salary")
    @Result(property = "desiredIndustry", column = "desired_industry")
    @Result(property = "desiredLocation", column = "desired_location")
    @Result(property = "desiredJob", column = "desired_job")
    Intention getIntentionByEmail(String email);

    @Insert("insert into intention(uid,annual_salary,desired_industry,desired_location,desired_job) values(#{uid},#{intentionData.annualSalary},#{intentionData.desiredIndustry},#{intentionData.desiredLocation},#{intentionData.desiredJob})")
    @Result(property = "annualSalary", column = "annual_salary")
    @Result(property = "desiredIndustry", column = "desired_industry")
    @Result(property = "desiredLocation", column = "desired_location")
    @Result(property = "desiredJob", column = "desired_job")
    void insertIntention(@Param(value = "uid") long uid, @Param(value = "intentionData") Intention intentionData);

    @Update("update intention set annual_salary=#{intentionData.annualSalary},desired_industry=#{intentionData.desiredIndustry},desired_location=#{intentionData.desiredLocation},desired_job=#{intentionData.desiredJob} where uid=#{uid}")
    @Result(property = "annualSalary", column = "annual_salary")
    @Result(property = "desiredIndustry", column = "desired_industry")
    @Result(property = "desiredLocation", column = "desired_location")
    @Result(property = "desiredJob", column = "desired_job")
    void updateIntention(@Param(value = "uid") long uid, @Param(value = "intentionData") Intention intentionData);

    //查询是否存在个人信息
    @Select("select count(*) from user_info where uid=#{id}")
    int selectByUid(int id);

    //用于给管理员查询未审核的就业倾向
    @Select("select intention.annual_salary,intention.desired_industry,intention.desired_location,intention.desired_job from intention order by pass")
    @Result(property = "annualSalary", column = "annual_salary")
    @Result(property = "desiredIndustry", column = "desired_industry")
    @Result(property = "desiredLocation", column = "desired_location")
    @Result(property = "desiredJob", column = "desired_job")
    List<Intention> adminSelect();
}
